package com.example.springboot_test.design_mode.proxy.dynamic_proxy;

import java.lang.reflect.Proxy;

public class MatchMakingTestDrive {
    public static void main(String[] args) {
        MatchMakingTestDrive matchMakingTestDrive = new MatchMakingTestDrive();
        matchMakingTestDrive.drive();
    }
    public void drive(){
        PersonBean personBean=new PersonBeanImpl();
        personBean.setGender("男");
        personBean.setInterests("按摩");
        personBean.setName("小四");
        personBean.setHotOrNotRating(10);
        PersonBean ownerProxy = getOwnerProxy(personBean);
        ownerProxy.setInterests("钓鱼");
        System.out.println("兴趣爱好设置");
        try {
            ownerProxy.setHotOrNotRating(100);
        } catch (Exception e) {
            System.out.println("不能设置自己的热度");
            e.printStackTrace();
        }
        String gender = ownerProxy.getGender();
        System.out.println(gender);

        int hotOrNotRating = ownerProxy.getHotOrNotRating();
        System.out.println("自己的热度"+hotOrNotRating);
    }

    PersonBean getOwnerProxy(PersonBean personBean){
        PersonBean person = (PersonBean) Proxy.newProxyInstance(personBean.getClass().getClassLoader(), personBean.getClass().getInterfaces(), new OwnInvocationHandler(personBean));
        return person;
    }
}
